Skip to content

feat(web): Add org removal functionality to admin user details page#38013

Open
karthikbhandary2 wants to merge 4 commits into
go-gitea:mainfrom
karthikbhandary2:org-remove
Open

feat(web): Add org removal functionality to admin user details page#38013
karthikbhandary2 wants to merge 4 commits into
go-gitea:mainfrom
karthikbhandary2:org-remove

Conversation

@karthikbhandary2

Copy link
Copy Markdown
Contributor

Related Issues

Closes #37071

Summary

Adds the ability for administrators to remove users from organizations directly from the admin user details page (/-/admin/users/{userid}). This feature provides both individual organization removal and bulk removal from all organizations.

Motivation

Currently, administrators need to navigate to each organization separately to remove a user from multiple organizations. This enhancement streamlines user management by allowing admins to perform these actions directly from the user details page.

Implementation

Backend (Go)

routers/web/admin/users.go (Modified)
  • Added RemoveUserFromOrg() - Removes a user from a single organization
  • Added RemoveUserFromAllOrgs() - Removes a user from all organizations
  • Both functions reuse the existing org_service.RemoveOrgUser() service
  • Handles edge cases:
    • Last owner protection (cannot remove if user is the only owner)
    • Partial removal tracking (shows count of successful removals)
    • Empty organization list
  • Added org_service import
routers/web/web.go (Modified)
  • Registered POST route: /{userid}/orgs/{orgid}/remove
  • Registered POST route: /{userid}/orgs/remove-all

Frontend (Templates)

templates/admin/user/view.tmpl (Modified)
  • Added "Remove All" button in the Organizations section header
  • Added confirmation modal for "Remove All" action with:
    • Descriptive warning message
    • User name and organization count
    • Cancel and confirm buttons
templates/admin/user/view_orgs.tmpl (New)
  • Custom organization list template with individual "Remove" buttons
  • Based on explore/user_list.tmpl but with admin-specific actions
  • Shows organization details:
    • Name
    • Visibility
    • Join date
  • Individual "Remove" button for each organization

Localization

options/locale/locale_en-US.json (Modified)

Added:

  • admin.users.org_removed - Success message for single removal
  • admin.users.all_orgs_removed - Success message for bulk removal
  • admin.users.no_orgs_to_remove - Info message when user has no organizations
  • admin.users.no_orgs_removed - Error message when no removals succeeded
  • admin.users.some_orgs_removed - Partial success message with count
  • admin.users.remove_all_orgs_title - Modal title
  • admin.users.remove_all_orgs_desc - Modal confirmation message

Tests

tests/integration/admin_user_org_test.go (New)
  • TestAdminRemoveUserFromOrg - Tests single organization removal
  • TestAdminRemoveUserFromAllOrgs - Tests bulk removal from all organizations
  • Verifies database state changes
  • Tests with non-owner users to avoid last-owner constraint

Features

  • ✅ Remove user from a single organization
  • ✅ Remove user from all organizations with confirmation
  • ✅ Last owner protection (prevents removing if user is the sole owner)
  • ✅ Graceful error handling with informative messages
  • ✅ Partial removal tracking (shows how many removals succeeded)
  • ✅ Integration tests

UI Changes

Before

No option to remove users from organizations on the admin user page.

After

  1. "Remove All" button at the top-right of the Organizations section
  2. Individual "Remove" button next to each organization
  3. Confirmation modal for bulk removal

Screenshots

image image

Security Considerations

  • Reuses existing org_service.RemoveOrgUser() which includes proper permission checks
  • CSRF protection on all POST requests
  • Only accessible to administrators
  • Cannot remove the last owner of an organization

Testing

Run integration tests:

go test -v ./tests/integration -run TestAdminRemoveUserFrom

Development Note

This PR was developed with assistance from Amazon Q Developer and Gemini.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 6, 2026
@karthikbhandary2 karthikbhandary2 marked this pull request as ready for review June 7, 2026 07:50
@github-actions github-actions Bot added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jun 7, 2026
Comment thread options/locale/locale_en-US.json
orgs, err := db.Find[org_model.Organization](ctx, org_model.FindOrgOptions{
ListOptions: db.ListOptionsAll,
UserID: u.ID,
IncludeVisibility: structs.VisibleTypePrivate,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this option should be given?

@karthikbhandary2 karthikbhandary2 Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is given because we are going to remove the user from all the orgs (including limited and private). Since this is behind admin only route, it is restricted to only admins and regular users cant see this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this option mean it only includes private organizations?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it means give everything (public, limited and private) and not to filter them out.

Comment thread routers/web/admin/users.go Outdated
Signed-off-by: techknowlogick <techknowlogick@gitea.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add Admin "Exit" Functionality for Organizations in User Details

4 participants